"use strict"

import Router from "koa-router";
import { getHash } from '../utils';
import { createUser, getUserByUsername } from "../models";
import { isLocalAuthenticated ,isBearerAuthenticated } from '../auth';

const router = new Router();

router.post('/create', async(ctx, next) => {
	const user = await getUserByUsername(ctx.request.body.username);
	console.log(user);
	if(user){
		ctx.body = {
			status:0,
			info:"用户已存在"
		}
	}else{
		ctx.body = {
			status:1,
			info:"",
			data:await createUser({
				username:ctx.request.body.username,
				password:getHash(ctx.request.body.password)
			})
		} 		
	}
});



export default router.routes();